Skip to content

Conversation

@wtrocki
Copy link
Member

@wtrocki wtrocki commented Mar 10, 2025

Collection Identifier camelCase Rule (xgen-IPA-102-collection-identifier-camelCase):

Enforces camelCase naming convention for resource identifiers
Prevents use of kebab-case, snake_case, or PascalCase
Also validates custom method names in the path

@wtrocki wtrocki changed the base branch from main to CLOUDP-304930 March 10, 2025 16:14
@wtrocki wtrocki force-pushed the CLOUDP-304930 branch 3 times, most recently from d82590d to a8e254c Compare March 10, 2025 16:44
@wtrocki wtrocki changed the base branch from CLOUDP-304930 to main March 10, 2025 16:45
@wtrocki wtrocki force-pushed the CLOUDP-304929 branch 2 times, most recently from b4350a1 to e5e3d89 Compare March 10, 2025 20:00
@wtrocki wtrocki changed the title Cloudp 304929 @wtrocki CLOUDP-304929: xgen-IPA-102-collection-identifier-camelCase Mar 10, 2025
@wtrocki wtrocki changed the title @wtrocki CLOUDP-304929: xgen-IPA-102-collection-identifier-camelCase CLOUDP-304929: xgen-IPA-102-collection-identifier-camelCase Mar 10, 2025
@wtrocki wtrocki marked this pull request as ready for review March 10, 2025 20:01
@wtrocki wtrocki requested a review from a team as a code owner March 10, 2025 20:01
@wtrocki wtrocki marked this pull request as draft March 10, 2025 20:11
@wtrocki
Copy link
Member Author

wtrocki commented Mar 10, 2025

Will apply approach for each path based on @lovisaberggren comment and also style from refactor PR. Back to draft

@wtrocki wtrocki marked this pull request as ready for review March 11, 2025 09:16
* @param {string} str - The string to check
* @returns {boolean} - True if the string is in camelCase, false otherwise
*/
export function isCamelCase(str) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI there is a spectral function we can use to check camel case
import { casing } from '@stoplight/spectral-functions'; like here https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/functions/eachCustomMethodMustUseCamelCase.js#L3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered it but preference is to have casing defined. Will change it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the spectral function, see

function: pattern # casing?
functionOptions:
match: "/^[a-z$_]{1}[A-Z09$_]*/" # type: camel ?
where the current regex is broken and could've been a built-in spectral check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also

function: pattern # casing?
functionOptions:
match: "^[A-Z].*" # type: pascal ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use this helper function? We can remove it if we are going with Spectral function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing helper.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


function checkViolations(pathKey, path) {
const violations = [];
const pathSegments = pathKey.split('/').filter((segment) => segment.length > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to slice the prefix before looking at collectionIdentifiers
(Similar to here

)

Copy link
Member Author

@wtrocki wtrocki Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with ignoring some specific use cases rather than having prefix.
In this case we need v2 to be ignored.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Used spectral native way to configure values.
Will fix eachPathAlternatesBetweenResourceNameAndPathParam.js file once we review this PR and approve it.

Will update our spec to avoid hardcoded values that depend on downstream schema.

if (!segment) return;

// Skip path parameter validation if it matches the expected format
if (isPathParam(segment)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we are not skipping pathParams, instead we are still validating them. This rule should look for collectionIdentifiers only

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not skipping

We do not have rule to cover validation for path param

collectionIdentifiers only

Currently we do have those as part of the collection identifiers. e.g

paths./api/atlas/v2/groups/{groupId}/clusters/{clusterName}/globalWrites/managedNamespaces.delete

I did checked briefly and could not find an rule to validate camel case for path params.
No strong opinion on my side. I have documented this rule to cover path params as well but can change it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards checking for more use cases (and documenting those).
Leaving with no action however happy to change it if we do have specific validation for this already or based on your feedback and opinion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is no guideline about path param (i.e. resourceID) format in IPA-102. Maybe we can consider validating it after defining a guideline about resourceID format and then validating with a rule that just looks for that guideline. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. We need to update rule description and name to reflect that it validates whole path correctness.
Then we can do all validation here. Thank you @yelizhenden-mdb

}

// Skip empty identifiers
if (identifier.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not think of any empty identifier case? Do we expect such cases like /api/atlas/v2/resource/:customMethod

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect such cases like /api/atlas/v2/resource/:customMethod

My approach is to cover all possible cases and have clear handling for those.
Since you made comment I think we can have it as error use case?
WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can have it as test case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Adding extra details and tests.

@wtrocki
Copy link
Member Author

wtrocki commented Mar 11, 2025

Noticed I missed test for //. Will add it in follow up PR

Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some nits and one Q

Comment on lines +58 to +69
paths: {
'/resource_groups': {},
},
},
errors: [
{
code: 'xgen-IPA-102-collection-identifier-camelCase',
message:
"Collection identifiers must be in camelCase. Path segment 'resource_groups' in path '/resource_groups' is not in camelCase. http://go/ipa/102",
path: ['paths', '/resource_groups'],
severity: DiagnosticSeverity.Warning,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: If the path is for example /resource_groups/{id}/resource_keys, will there be two errors, one for resource_groups and one for resource_keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single violation with 2 errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, could you add a test case for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extended multiple test cases.

@wtrocki wtrocki requested a review from lovisaberggren March 11, 2025 17:16
Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY!

@wtrocki wtrocki merged commit 246df4d into main Mar 11, 2025
13 checks passed
@wtrocki wtrocki deleted the CLOUDP-304929 branch March 11, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants